#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<chrono>
#include<unordered_map>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
const int maxn=3e5+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
template<typename A,typename B>
struct unmap{
    struct node{
        A u; B v; int nxt;
    };
    static const unsigned uN=20000003;
    vector<node> e;
    int head[uN];
    unmap(){memset(head,-1,sizeof(head));}
    bool count(A u){
        int hs=u%uN;
        for(int i=head[hs]; ~i; i=e[i].nxt)
            if(e[i].u==u) return 1;
        return 0;
    }
    B &operator[](A u){
        int hs=u%uN;
        for(int i=head[hs]; ~i; i=e[i].nxt)
            if(e[i].u==u) return e[i].v;
        e.push_back({u,B(),head[hs]}),head[hs]=e.size()-1;
        return e.back().v;
    }
};
LL b[maxn];
unmap<LL,LL>cnt;
int main(void)
{
  LL n,m;n=read();m=read();
  for(int i=1;i<=n;i++){
     LL x;x=read();
     cnt[x]++;
  }
  for(int i=1;i<=m;i++){
     b[i]=read();
  }
  LL sum=0;
  for(int i=1;i<=m;i++){
     bitset<30>q=b[i];
     for(int x=0;x<30;x++){
        for(int y=0;y<x;y++){
            bitset<30>t=q;
            t.flip(x);t.flip(y);
            LL ans=t.to_ulong();
            if(cnt.count(ans)) sum+=cnt[ans];
        }
     }
  }
  printf("%lld\n",sum);
return 0;
}
